const BasePlugin = require('./base-plugin');

class SimpleRecallPlugin extends BasePlugin {
    constructor() {
        super();
        this.name = '简单撤回监控';
        this.priority = 99; // 高优先级
        this.messageCache = new Map();
    }

    // 缓存消息
    onGroupMessage(event, reply) {
        if (event.message_id) {
            this.messageCache.set(event.message_id, {
                user: event.user_id,
                msg: event.raw_message
            });
        }
        return false;
    }

    onPrivateMessage(event, reply) {
        if (event.message_id) {
            this.messageCache.set(event.message_id, {
                user: event.user_id, 
                msg: event.raw_message
            });
        }
        return false;
    }

    // 处理撤回
    onGroupRecall(event, reply) {
        const msg = this.messageCache.get(event.message_id);
        if (msg) {
            reply(`🗑️ @${msg.user} 撤回：${msg.msg}`);
            this.messageCache.delete(event.message_id);
        } else {
            reply(`🗑️ @${event.user_id} 撤回了消息`);
            
        }
        return true;
    }

    onFriendRecall(event, reply) {
        const msg = this.messageCache.get(event.message_id);
        if (msg) {
            reply(`🗑️ @${msg.user} 私聊撤回：${msg.msg}`);
            this.messageCache.delete(event.message_id);
        } else {
            reply(`🗑️ @${event.user_id} 私聊撤回了消息`);
        }
        return true;
    }
}

module.exports = SimpleRecallPlugin;